package com.cskaoyan.day16;

import java.util.Random;

public class CodeTest {
    public static void main(String[] args) {
        int count = 0;
        while (count++ != 10) {
            System.out.println("第" + count + "次实验");
            String code = codeGenerate();
            for (int i = 0; i < 1000; i++) {
                String str = "";
                if (i < 10) {
                    str = "00" + i;
                } else if (i < 100) {
                    str = "0" + i;
                } else {
                    str += i;
                }
                if (code.equals(str)) {
                    System.out.println("破解成功！密码是" + str);
                }
            }
            System.out.println("-------------------");
        }
    }

    public static String codeGenerate() {
        Random random = new Random();
        int randomNumber = random.nextInt(10); // 生成0到9之间的随机数
        StringBuilder sb = new StringBuilder("" + randomNumber);
        sb.append(random.nextInt(10));
        sb.append(random.nextInt(10));
        System.out.println("生成成功，为:" + sb);
        return sb.toString();
    }
}
